package com.spring.cold.security;

import org.springframework.security.core.context.SecurityContextHolder;

public class Securitys {

  private static CustomizeUser getCustomizeUser(){
    Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    if (o instanceof String && "anonymousUser".equals(o)){
      return null;
    }
    return (CustomizeUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  }

  public static String getName(){
    if (getCustomizeUser()!=null){
      return getCustomizeUser().getName();
    }
    return null;
  }

  public static String getUserId(){
    if (getCustomizeUser()!=null){
      return getCustomizeUser().getId();
    }
    return null;
  }

  public static String getIsAdmin(){
    return getCustomizeUser().getIsAdmin();
  }

}
